package com.lhn.bbs.controller;

import com.lhn.bbs.dto.ActionResult;
import com.lhn.bbs.service.ThemeService;
import com.lhn.bbs.vo.ReplyAddVo;
import com.lhn.bbs.vo.ThemeAddVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;


/**
 * @ Author :lihainan
 * @ ClassNmae :ThemeController
 * @ Description :TODO
 * @ Date :2021/4/1
 * @ Version 1.0
 */
@RestController
@Slf4j
@RequestMapping("/theme")
public class ThemeController {

    @Autowired
    private ThemeService themeService ;

    /**
     * 查询最新主题
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping(value = "/nthemeall",method = RequestMethod.GET)
    public ActionResult newthemeall(@RequestParam(value="page",defaultValue="1")Integer page,
                                    @RequestParam(value = "limit", defaultValue = "3") Integer limit){
//        log.info("======="+page+"===="+limit);
        return themeService.findNewThemeAll(page,limit);
    }

    /**
     * 根据板块id查询主题
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping(value = "/pthemeall",method = RequestMethod.GET)
    public ActionResult pthemeall(@RequestParam(value="page",defaultValue="1")Integer page,
                                    @RequestParam(value = "limit", defaultValue = "3") Integer limit,
                                    @RequestParam(value = "plateid") Integer plateid){
        log.info("======="+page+"===="+limit+"====="+plateid);
        return themeService.findpThemeAll(page,limit,plateid);
    }

    /**
     * 查询帖子详情及回复帖内容与高频词提取功能
     * @param themeid
     * @return
     */
    @RequestMapping(value = "/themeone",method = RequestMethod.GET)
    public ActionResult newthemeall(@RequestParam Integer themeid,
                                    @RequestParam(value="page",defaultValue="1")Integer page,
                                    @RequestParam(value = "limit", defaultValue = "3") Integer limit){
//        log.info("======="+themeid+"====");
        return themeService.findNewThemeOne(themeid,page,limit);

    }

    /**
     *  主题帖的发布
     * @param themeAddVo
     * @return
     */
    @RequestMapping(value = "/themeadd",method = RequestMethod.POST)
    public ActionResult themeadd(@RequestBody ThemeAddVo themeAddVo){

        SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date(System.currentTimeMillis());
//        System.out.println(formatter.format(date));
        String format = formatter.format(date);
        themeAddVo.setThemetime(format);
        log.info("发布帖子============"+themeAddVo);

        return  themeService.themeAdd(themeAddVo);
    }

    /**
     * 添加班级主题
     * @param themeAddVo
     * @return
     */
    @RequestMapping(value = "/themeclassadd",method = RequestMethod.POST)
    public ActionResult themeclassadd(@RequestBody ThemeAddVo themeAddVo){

        SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date(System.currentTimeMillis());
//        System.out.println(formatter.format(date));
        String format = formatter.format(date);
        themeAddVo.setThemetime(format);
        log.info("发布帖子============"+themeAddVo);

        return  themeService.themeClassAdd(themeAddVo);
    }

    /**
     * 帖子的搜索查询
     * @param themeAddVo
     * @return
     */
    @RequestMapping(value = "/liketheme",method = RequestMethod.GET)
    public ActionResult liketheme(@RequestParam String likename,
                                  @RequestParam(value="page",defaultValue="1")Integer page,
                                  @RequestParam(value = "limit", defaultValue = "3") Integer limit){

       log.info("===="+likename);

        return  themeService.likefindByname(likename,page,limit);
    }

    /**
     * 根据主题创建人查询
     * @param page
     * @param limit
     * @param userid
     * @return
     */
    @RequestMapping(value = "/onetheme",method = RequestMethod.GET)
    public ActionResult oneTheme(@RequestParam(value="page",defaultValue="1")Integer page,
                                    @RequestParam(value = "limit", defaultValue = "3") Integer limit,
                                    @RequestParam(value = "userid") Integer userid){
//        log.info("======="+page+"===="+limit);
        return themeService.findOneThemeAll(page,limit,userid);
    }

    /**
     * 根据themeid删除帖子
     * @param themeid  帖子id
     * @return  返回值为ActionResult类型
     */
    @RequestMapping(value = "/deletetheme",method = RequestMethod.GET)
    public ActionResult deleteTheme(@RequestParam(value = "themeid") Integer themeid){

        log.info("======="+themeid+"====");

        return themeService.deleteTheme(themeid);
    }



}
